From 2fcaf264442524627eb06feb2520541e0e3d6cf3 Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Fri, 30 May 2025 17:53:04 +0200 Subject: [PATCH] fix(readonly): avoid changing permissions when not needed in FilePermissionsRestore, first checks the folder permissions before changing them will avoid useless call changing permissions when not needed Signed-off-by: Matthieu Gallien --- src/libsync/filesystem.cpp | 9 +++++---- test/testpermissions.cpp | 4 ---- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/libsync/filesystem.cpp b/src/libsync/filesystem.cpp index 515d02b15..5603e4f4e 100644 --- a/src/libsync/filesystem.cpp +++ b/src/libsync/filesystem.cpp @@ -648,12 +648,13 @@ FileSystem::FilePermissionsRestore::FilePermissionsRestore(const QString &path, { try { - const auto stdStrPath = _path.toStdWString(); - _initialPermissions = FileSystem::isFolderReadOnly(stdStrPath) ? OCC::FileSystem::FolderPermissions::ReadOnly : OCC::FileSystem::FolderPermissions::ReadWrite; - if (_initialPermissions != temporaryPermissions) { + const auto &stdStrPath = _path.toStdWString(); + const auto fsPath = std::filesystem::path{stdStrPath}; + if ((temporaryPermissions == OCC::FileSystem::FolderPermissions::ReadOnly && !FileSystem::isFolderReadOnly(fsPath)) || + (temporaryPermissions == OCC::FileSystem::FolderPermissions::ReadWrite && FileSystem::isFolderReadOnly(fsPath))) { + FileSystem::setFolderPermissions(_path, temporaryPermissions); _rollbackNeeded = true; } - FileSystem::setFolderPermissions(_path, temporaryPermissions); } catch (const std::filesystem::filesystem_error &e) { diff --git a/test/testpermissions.cpp b/test/testpermissions.cpp index f04f14b00..5de4c4dd6 100644 --- a/test/testpermissions.cpp +++ b/test/testpermissions.cpp @@ -278,11 +278,7 @@ private slots: //4. File should be updated, that's tested by assertLocalAndRemoteDir QCOMPARE(currentLocalState.find("normalDirectory_PERM_CKDNV_/canBeModified_PERM_W_.data")->size, canBeModifiedSize + 1); -#if defined Q_OS_WINDOWS - QCOMPARE(currentLocalState.find("readonlyDirectory_PERM_M_/canBeModified_PERM_W_.data")->size, canBeModifiedSize); -#else QCOMPARE(currentLocalState.find("readonlyDirectory_PERM_M_/canBeModified_PERM_W_.data")->size, canBeModifiedSize + 1); -#endif //5. // the file should be in the server and local -- 2.30.2